package com.neusoft.neuiotms.dcam.fixed.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.neuiotms.dcam.fixed.converter.InventoryDutyHistoryConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.InventoryDutyHistoryDTO;
import com.neusoft.neuiotms.dcam.fixed.model.InventoryDutyHistory;
import com.neusoft.neuiotms.dcam.fixed.repository.InventoryDutyHistoryRepository;
import com.neusoft.neuiotms.dcam.fixed.service.InventoryDutyHistoryService;

@Service
public class InventoryDutyHistoryServiceImpl implements InventoryDutyHistoryService {

    @Autowired
    private InventoryDutyHistoryRepository repository;
    @Autowired
    private InventoryDutyHistoryConverter converter;

    @Override
    public List<InventoryDutyHistoryDTO> findByDuty(String dutyCode) {
        final List<InventoryDutyHistory> modelList = this.repository.findByDutyCodeOrderByCreateTimeDesc(dutyCode);
        final List<InventoryDutyHistoryDTO> dtoList = this.converter.toListDTO(modelList);
        return dtoList;
    }

    @Override
    public void create(InventoryDutyHistoryDTO dto) {
        final InventoryDutyHistory model = this.converter.toModel(dto);
        this.repository.save(model);
    }

}
